package day52.org.service.impl;

import day52.basic.constants.Constant;
import day52.basic.service.impl.BaseServiceImpl;
import day52.org.domain.Dictionarydetail;
import day52.org.domain.Dictionarytype;
import day52.org.mapper.DictionarydetailMapper;
import day52.org.mapper.DictionarytypeMapper;
import day52.org.service.IDictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DictionarytypeServiceImpl extends BaseServiceImpl<Dictionarytype> implements IDictionarytypeService {

    @Autowired
    private DictionarydetailMapper dictionarydetailMapper;
    @Autowired
    private DictionarytypeMapper dictionarytypeMapper;

    @Override
    @Transactional
    public void delete(Long id) {
        List<Dictionarydetail> all = dictionarydetailMapper.findAllByTypes_id(id);
        for (Dictionarydetail dictionarydetail : all) {
            Long id1 = dictionarydetail.getId();
            dictionarydetailMapper.delete(id1);
        }
        dictionarytypeMapper.delete(id);
    }
}
